<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript">
$(function(){
	$('#tblListAbnormaltime').datagrid({
		title: '',
		fit: true,
		nowrap: false,
		striped: true,
		url: '<c:url value="/system/abnormaltime/jsonAbnormaltimePageList.do"/>',
		sortName: 'begintime',
		sortOrder: 'asc',
		remoteSort: true,
		idField: 'id',
		frozenColumns:[[
		    {field:'ck',checkbox:true}            
		]],
		columns: [[
			{field:'begintime',title:'开始时间',width:300,sortable:true},
			{field:'endtime',title:'结束时间',width:300}
		]],
		pageSize: 20,
		pagination: true,
		rownumbers: true,
		toolbar:[{
			text:'新增',
			iconCls:'icon-add',
			handler:function(){
				newAbnormaltime();
		}},{
			text:'修改',
			iconCls:'icon-edit',
			handler:function(){
				editAbnormaltime();
		}},{
			id:'btnOnlineDel',
			text:'删除',
			iconCls:'icon-remove',
			handler:function(){
				delAbnormaltime();
		}}],
		onClickRow:function(rowIndex, rowData) {
			$('#tblListAbnormaltime').datagrid('clearSelections').datagrid('selectRow',rowIndex);	
		}
	});
})

function newAbnormaltime(){
	$('#frmAbnormaltime input[name="id"]').val('');
	$('#frmAbnormaltime input[name="begintime"]').val('');
	$('#frmAbnormaltime input[name="endtime"]').val('');
	$('#dlgAbnormaltime').dialog({
		title:'新增异常上网时间',
		modal:true,
		closable:true,
		draggable:false,
		width:350,
		height:150,
		toolbar:[{
			text:'保存',
			iconCls:'icon-save',
			handler:function(){
				saveAbnormaltime();
			}
		},{
			text:'关闭',
			iconCls:'icon-cancel',
			handler:function(){
				$('#dlgAbnormaltime').dialog('close');
			}
		}]
	}).dialog('open');
}

function editAbnormaltime(){
	var rows = $('#tblListAbnormaltime').datagrid('getSelections').length;
	if(rows>1){
		$.messager.alert('消息', '一次只能修改一条记录！', 'info');
	}else{
		if(rows==0){
			$.messager.alert('消息', '没有选中任何记录！', 'info');
		}else{
			var rowdata = $('#tblListAbnormaltime').datagrid('getSelected');
			$('#frmAbnormaltime').form('load', rowdata);
			$('#dlgAbnormaltime').dialog({
				title:'修改推荐上网时长',
				modal:true,
				closable:true,
				draggable:false,
				width:350,
				height:150,
				toolbar:[{
					text:'保存',
					iconCls:'icon-save',
					handler:function(){
					saveAbnormaltime();
					}
				},{
					text:'关闭',
					iconCls:'icon-cancel',
					handler:function(){
						$('#dlgAbnormaltime').dialog('close');
					}
				}]
			}).dialog('open');
		}
	}
}

function saveAbnormaltime(){
	if ($('#frmAbnormaltime').form('validate')) {
		var data = $('#frmAbnormaltime').serialize();
		$.ajax({
			url: '<c:url value="/system/abnormaltime/doSaveAbnormaltime.do"/>',
			type: 'POST',
			data: data,
			beforeSend: function(XmlHttpRequest, textStatus, errorThrown) {
				$.messager.progress({
					title:'提示',
					msg:'正在执行数据操作，请稍待...'
				});
			},
			success: function(result) {
				$.messager.progress('close');
				if(!result.success) {
					$.messager.alert('错误', result.data, 'error');
				}
				else {
					$.messager.alert('提示', result.data, 'info');	
					$('#tblListAbnormaltime').datagrid('clearSelections').datagrid('reload');
					$('#dlgAbnormaltime').dialog('close');
				}
			},
			complete: function (XMLHttpRequest, textStatus) {
			}
		});
	}
}

function delAbnormaltime(){
	var rows = $('#tblListAbnormaltime').datagrid('getSelections');
	var ids = [];
	for (var i=0; i<rows.length; i++) {
		ids.push(rows[i].id);
	}
	ids.join(',');
	if (0 == ids.length) {
		$.messager.alert('消息', '请选择要删除的记录！', 'info');
	}else{
		$.messager.confirm('删除数据', '确定要删除所选择的记录？', function(r){
			if (r){
				$.ajax({
					url: "<c:url value='/system/abnormaltime/doDelAbnormaltime.do' />",
					type: 'POST',
					data: 'ids='+ids,
					beforeSend: function(XmlHttpRequest, textStatus, errorThrown) {
						$.messager.progress({
							title:'提示',
							msg:'正在执行数据操作，请稍待...'
						});
					},
					success: function(result) {
						$.messager.progress('close');
						if(!result.success) {
							$.messager.alert('消息', result.data, 'info');
						}
						else {
							$.messager.alert('提示', result.data, 'info');
							$('#tblListAbnormaltime').datagrid('clearSelections').datagrid('reload');
						}
					},
					complete: function (XMLHttpRequest, textStatus) {
					}
				});
			}
		});	
	}
}
</script>
<div id="abnormaltimeLayout" class="easyui-layout" fit="true">
	<div id="abnormaltimeCenter" region="center">
		<table id="tblListAbnormaltime" border="false"></table>
	</div>
</div>
<div style="display:none;">
	<div id="dlgAbnormaltime" class="easyui-dialog" closed="true">
		<div style="padding:5px;">
			<form id="frmAbnormaltime" method="post" style="margin:0;padding:0">
			<table align="center"  cellpadding="0" cellspacing="0">
				<tr>
					<td><font color="red">*</font>开始时间：</td>
					<td>
						<input id="begintime" name="begintime" style="width:200px" class="easyui-validatebox" required="true" maxlength="8"/>
						<input type="hidden" id="id" name="id" />
						<input type="hidden" id="type" name="type" />
						<input type="hidden" id="usercode" name="usercode" />
					</td>
				</tr>
				<tr>
					<td><font color="red">*</font>结束时间：</td>
					<td>
						<input id="endtime" name="endtime" style="width:200px" class="easyui-validatebox" required="true" maxlength="8"/>
					</td>
				</tr>
			</table>
			</form>
		</div>			
	</div>
</div>